<template>
	<view class="groupmanageinfo">
		<view v-if="form.is_audit==1||form.is_audit==2"
			:class="form.is_audit==2?'text-c f-13 mt-15 c-red':'text-c f-13 mt-15'">
			<text>{{form.refuse_reason}}</text>
		</view>
		<view v-if="form.is_audit==0||form.is_audit==3" style="padding: 30rpx;">
			<view class="groupmanage_input_box">
				<view class="f-14 mr-10 label">车友会名称</view>
				<input class="flex-1" v-model="form.title" placeholder="设置车友会名称" />
			</view>
			<view class="groupmanage_input_box">
				<view class="f-14 mr-10 label">车友会英文名</view>
				<input class="flex-1" v-model="form.car_model" placeholder="设置车友会英文名;例:SUBARU-BEIJING" />
			</view>
			<view class="groupmanage_img">
				<view class="f-14 mr-10 label">车友会头像</view>
				<view class="group_logo_content">
					<image v-if="form.logo" class="group_logo" :src="picUrl+form.logo" mode="aspectFill"
						@click="uploadLogo">
					</image>
					<view v-else class="group_logo_block" @click="uploadLogo">
						<view class="add">+</view>
						<view class="marker">添加头像</view>
					</view>
					<view class="info">
						<view class="text">
							<view>格式: JPG/PNG/GIF</view>
							<view>尺寸: 比例为1:1,小于200kb</view>
						</view>

					</view>
				</view>
			</view>
			<view class="groupmanage_img">
				<view class="f-14 mr-10 label">车友会封面</view>
				<view class="group_logo_content">
					<image v-if="form.pic" class="group_pic" :src="picUrl+form.pic" mode="aspectFill"
						@click="uploadPic">
					</image>
					<view v-else class="group_pic_block" @click="uploadPic">
						<view class="add">+</view>
						<view class="marker">添加封面</view>
					</view>
					<view class="info">
						<view class="text">
							<view>格式: JPG/PNG/GIF</view>
							<view>尺寸: 750X375,小于500kb</view>
						</view>
					</view>
				</view>
			</view>
			<view class="groupmanage_textarea">
				<view class="f-14 mr-10 mt-15 label">车友会简介</view>
				<textarea class="textarea" v-model="form.desc" placeholder="请添加车友会简介(限1000字)" maxlength="1000"
					:disable-default-padding="true"></textarea>
			</view>
			<view class="group_public_btn_block mt-30" @click="submitForm">保存</view>
		</view>
		<view v-if="form.is_audit==1||form.is_audit==2" class="mt-15">
			<view v-if="isChange==1" class="pd-30">
				<view class="groupmanage_input_box">
					<view class="f-14 mr-10 label">车友会名称</view>
					<input class="flex-1" v-model="form.title_audit" placeholder="设置车友会名称" />
				</view>
				<view class="groupmanage_input_box">
					<view class="f-14 mr-10 label">车友会英文名</view>
					<input class="flex-1" v-model="form.car_model_audit" placeholder="设置车友会英文名;例:SUBARU-BEIJING" />
				</view>
				<view class="groupmanage_img">
					<view class="f-14 mr-10 label">车友会头像</view>
					<view class="group_logo_content">
						<image v-if="form.logo_audit" class="group_logo" :src="picUrl+form.logo_audit" mode="aspectFill"
							@click="uploadLogo">
						</image>
						<view v-else class="group_logo_block" @click="uploadLogo">
							<view class="add">+</view>
							<view class="marker">添加头像</view>
						</view>
						<view class="info">
							<view class="text">
								<view>格式: JPG/PNG/GIF</view>
								<view>尺寸: 比例为1:1,小于200kb</view>
							</view>

						</view>
					</view>
				</view>
				<view class="groupmanage_img">
					<view class="f-14 mr-10 label">车友会封面</view>
					<view class="group_logo_content">
						<image v-if="form.pic_audit" class="group_pic" :src="picUrl+form.pic_audit" mode="aspectFill"
							@click="uploadPic">
						</image>
						<view v-else class="group_pic_block" @click="uploadPic">
							<view class="add">+</view>
							<view class="marker">添加封面</view>
						</view>
						<view class="info">
							<view class="text">
								<view>格式: JPG/PNG/GIF</view>
								<view>尺寸: 750X375,小于500kb</view>
							</view>
						</view>
					</view>
				</view>
				<view class="groupmanage_textarea">
					<view class="f-14 mr-10 mt-15 label">车友会简介</view>
					<textarea class="textarea" v-model="form.desc_audit" placeholder="请添加车友会简介(限1000字)" maxlength="1000"
						:disable-default-padding="true"></textarea>
				</view>
				<view class="group_public_btn_block mt-30" @click="submitFormAudit">保存</view>
			</view>
			<view v-else>
				<view class="groupmanage_input_box_bk">
					<view class="groupmanage_input_box display_flex">
						<view class="f-14 mr-10">车友会名称</view>
						<view class="c-999999">{{form.title_audit}}</view>
					</view>
					<view class="groupmanage_input_box display_flex">
						<view class="f-14 mr-10">车友会英文名</view>
						<view class="c-999999">{{form.car_model_audit}}</view>
					</view>
				</view>
				<view class="groupmanage_input_box_bk mt-10">
					<view class="groupmanage_img" style="margin-top: 0;">
						<view class="f-14 mr-10 label">车友会头像</view>
						<view class="group_logo_content">
							<image v-if="form.logo_audit" class="group_logo" :src="picUrl+form.logo_audit"
								mode="aspectFill">
							</image>
							<view v-else class="group_logo_block">
								<view class="add">+</view>
								<view class="marker">添加头像</view>
							</view>
						</view>
					</view>
				</view>
				<view class="groupmanage_input_box_bk mt-10">
					<view class="groupmanage_img" style="margin-top: 0;">
						<view class="f-14 mr-10 label">车友会封面</view>
						<view class="group_logo_content">
							<image v-if="form.pic_audit" class="group_pic" :src="picUrl+form.pic_audit"
								mode="aspectFill">
							</image>
							<view v-else class="group_pic_block">
								<view class="add">+</view>
								<view class="marker">添加封面</view>
							</view>
						</view>
					</view>
				</view>
				<view class="groupmanage_input_box_bk mt-10">
					<view class="groupmanage_textarea" style="margin-top: 0;">
						<view class="f-14 mr-10 label">车友会简介</view>
						<view style="height: 160rpx;overflow-y: auto;padding: 20rpx 0;">
							<text>{{form.desc_audit}}</text>
						</view>
					</view>
				</view>
				<view class="pd-30">
					<view class="group_public_btn_block" @click="againForm">重新提交</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getAdminGroupInfo,
		submitAdminGroup,
		submitAdminGroupAudit,
		checkText
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				isChange: 0,
				form: {},
				isSubmit: true,
				picUrl: app.globalData.picUrl
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}
			if (uni.getStorageSync('userinfo').is_staff == 0) {
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		},
		onLoad(options) {
			if (uni.getStorageSync('userinfo').is_staff != 0) {
				this.club_id = options.club_id
				this.getAdminGroupInfo()
			}
			var params = {
				event_code: '车友会信息管理',
				path: 'pages/groupmanage/groupinfo',
				event_id: '',
				title: '',
				source_page: '',
				value: '',
			}
			app.BurialPoint(params)
		},
		methods: {
			getAdminGroupInfo() {
				getAdminGroupInfo({
					club_id: this.club_id
				}).then(res => {
					if (res.state == 1) {
						this.form = res.data.info
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			uploadLogo() {
				var that = this
				uni.chooseMedia({
					count: 1,
					mediaType: ['image'],
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						var tempFilePaths = res.tempFiles
						uni.uploadFile({
							url: app.globalData.uploadUrl,
							filePath: tempFilePaths[0].tempFilePath,
							name: 'img',
							success: (uploadFileRes) => {
								console.log(JSON.parse(uploadFileRes.data));
								var picdata = JSON.parse(uploadFileRes.data);
								if (that.isChange == 1) {
									that.form.logo_audit = picdata.data.img
								} else {
									that.form.logo = picdata.data.img
								}
							}
						});
					}
				});
			},
			uploadPic() {
				var that = this
				uni.chooseMedia({
					count: 1,
					mediaType: ['image'],
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						var tempFilePaths = res.tempFiles
						uni.uploadFile({
							url: app.globalData.uploadUrl,
							filePath: tempFilePaths[0].tempFilePath,
							name: 'img',
							success: (uploadFileRes) => {
								console.log(JSON.parse(uploadFileRes.data));
								var picdata = JSON.parse(uploadFileRes.data);
								if (that.isChange == 1) {
									that.form.pic_audit = picdata.data.img
								} else {
									that.form.pic = picdata.data.img
								}

							}
						});
					}
				});
			},
			submitForm() {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					if (that.form.title == '') {
						uni.showToast({
							title: '请填写车友会名称',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					if (that.form.logo == '') {
						uni.showToast({
							title: '请上传车友会LOGO',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					if (that.form.pic == '') {
						uni.showToast({
							title: '请上传车友会封面图',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					if (that.form.desc == '') {
						uni.showToast({
							title: '请填写车友会简介',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					var checktext = that.form.title + that.form.desc + that.form.car_model
					checkText({
						content: checktext,
					}).then(res => {
						if (res.state == 1) {
							uni.showModal({
								content: '确定保存吗？',
								confirmColor: '#00A0DC',
								success: function(res) {
									if (res.confirm) {
										submitAdminGroupAudit({
											club_id: that.form.club_id,
											title_audit: that.form.title,
											desc_audit: that.form.desc,
											logo_audit: that.form.logo,
											pic_audit: that.form.pic,
											car_model_audit: that.form.car_model,
										}).then(res => {
											if (res.state == 1) {
												uni.showToast({
													title: '保存成功',
													mask: true,
													icon: 'success',
													duration: 1500
												})
												that.isChange=0
												that.getAdminGroupInfo()
											} else {
												uni.showToast({
													title: res.error[0],
													mask: true,
													icon: 'none',
													duration: 1500
												})
											}
										})
										that.isSubmit = true
									} else if (res.cancel) {
										console.log('用户点击取消');
										that.isSubmit = true
									}
								}
							});
						} else {
							that.isSubmit = true
							uni.showToast({
								title: res.error[0],
								mask: true,
								icon: 'none',
								duration: 1500
							});
						}
					})

				}
			},
			submitFormAudit() {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					if (that.form.title_audit == '') {
						uni.showToast({
							title: '请填写车友会名称',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					if (that.form.logo_audit == '') {
						uni.showToast({
							title: '请上传车友会LOGO',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					if (that.form.pic_audit == '') {
						uni.showToast({
							title: '请上传车友会封面图',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					if (that.form.desc_audit == '') {
						uni.showToast({
							title: '请填写车友会简介',
							mask: true,
							icon: 'none',
							duration: 1500
						})
						that.isSubmit = true
						return false;
					}
					var checktext = that.form.title_audit + that.form.desc_audit + that.form.car_model_audit
					checkText({
						content: checktext,
					}).then(res => {
						if (res.state == 1) {
							uni.showModal({
								content: '确定保存吗？',
								confirmColor: '#00A0DC',
								success: function(res) {
									if (res.confirm) {
										submitAdminGroupAudit(that.form).then(res => {
											if (res.state == 1) {
												uni.showToast({
													title: '保存成功',
													mask: true,
													icon: 'success',
													duration: 1500
												})
												that.isChange=0
												that.getAdminGroupInfo()
											} else {
												uni.showToast({
													title: res.error[0],
													mask: true,
													icon: 'none',
													duration: 1500
												})
											}
										})
										that.isSubmit = true
									} else if (res.cancel) {
										console.log('用户点击取消');
										that.isSubmit = true
									}
								}
							});
						} else {
							that.isSubmit = true
							uni.showToast({
								title: res.error[0],
								mask: true,
								icon: 'none',
								duration: 1500
							});
						}
					})

				}
			},
			againForm() {
				this.isChange = 1
			}
		}
	}
</script>

<style lang="scss">
	.groupmanageinfo {


		.title {
			font-size: 32rpx;
			color: #000000;
			font-weight: 400;
		}

		.label {
			font-size: 28rpx;
			margin-bottom: 20rpx;
		}

		.groupmanage_input_box {
			font-size: 24rpx;
			margin-top: 30rpx;
			align-items: center;

			.flex-1 {
				border: 2rpx solid #e9e9e9;
				border-radius: 8rpx;
				height: 90rpx;
				line-height: 90rpx;
				padding: 0 28rpx;
				font-size: 24rpx;
			}
		}

		.groupmanage_input_box:first-child {
			margin-top: 0;
		}

		.groupmanage_img {
			margin-top: 30rpx;
			align-items: center;

			.group_logo_content {
				display: flex;

				.group_logo {
					width: 200rpx;
					height: 200rpx;
					border-radius: 8rpx;
					border: 2rpx solid #e9e9e9;
				}

				.group_logo_block {
					width: 198rpx;
					height: 198rpx;
					display: block;
					border-radius: 8rpx;
					font-size: 24rpx;
					color: #000000;
					background-color: #F7F7F7;
					text-align: center;
					padding-top: 40rpx;
					box-sizing: border-box;

					.add {
						width: 100%;
						font-size: 55rpx;
					}
				}

				.group_pic {
					width: 400rpx;
					height: 200rpx;
					border-radius: 8rpx;
					border: 2rpx solid #e9e9e9;
				}

				.group_pic_block {
					width: 400rpx;
					height: 200rpx;
					display: block;
					border-radius: 8rpx;
					font-size: 24rpx;
					color: #000000;
					background-color: #F7F7F7;
					text-align: center;
					padding-top: 40rpx;
					box-sizing: border-box;

					.add {
						width: 100%;
						font-size: 55rpx;
					}
				}

				.info {
					flex: 1;
					border: 2rpx solid #e9e9e9;
					border-radius: 8rpx;
					margin-left: 40rpx;
					font-size: 18rpx;
					color: #999999;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}

		.groupmanage_textarea {
			font-size: 24rpx;
			margin-top: 30rpx;

			.textarea {
				height: 200rpx;
				padding: 20rpx;
				border-radius: 8rpx;
				border: 2rpx solid #e9e9e9;
				box-sizing: border-box;
				width: 100%;
			}
		}

		.next_step_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 25rpx 0;
			margin: 60rpx 30rpx;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}

		.groupmanage_input_box_bk {
			padding: 30rpx;
			background-color: #f0f0f0;
		}
	}
</style>